<?php 	
include_once("../helper/DBOperation.php");
$dbObj = new DBOperation();

include("../helper/check_user_login.php");
checkUserIsLogin("admin");

include_once("includes/paging.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Welcome to Admin Panel</title>
	<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
	<div id="navigation">
		<div id="title">User Listing</div>
		<div id="nav"><a href="../unit_a.php">Go To Mobile Site</a> | <a href="add_user.php">Add User</a> | <a href="logout.php">Logout</a></div>
	</div>
	<div id="body">
		<div id="user_listing">
			<div id="error"><?php if(isset($_SESSION['error']) && $_SESSION['error']!="") { echo $_SESSION['error']; unset($_SESSION['error']); }?></div>
			<div id="success"><?php if(isset($_SESSION['success']) && $_SESSION['success']!="") { echo $_SESSION['success']; unset($_SESSION['success']); }?></div>
			<table align="center" id="listing" cellspacing="0" cellpadding="0">
				<tr>
					<th></th>
					<th>Username</th>
					<th>Email</th>
                    <th>Phone</th>
                    <th>Carrier</th>
					<th>Display Name</th>
					<th>Action</th>
					
				</tr>
				<?php 	$user = mysql_real_escape_string("admin");
						$query = "select * from tbl_users where is_admin=0";
						$total_records = mysql_num_rows(mysql_query($query));
						
					  	if($total_records>0){
							$i=1;
							$offset = 10;
							if(isset($_REQUEST['page']) && $_REQUEST['page']!=""){
								$page = $_REQUEST['page'];									
								$from 	= ($page * $offset) - $offset;													
							}else{
								$from = 0;
							}
							$query.= " limit " . $from . "," . $offset;
							$user_query = mysql_query($query);
					  		while($user_row = mysql_fetch_array($user_query)){
								if($i%2==0){
	 			 					$class = "class='row1'";
	  							}else{
	   								$class = "";
							 	}
				?>
				<tr <?php echo $class;?>>
					<td><?php echo $i;?></td>
					<td><?php echo $user_row['username'];?></td>
					<td><?php echo $user_row['email'];?></td>
                    <td><?php echo $user_row['phone'];?></td>
                    <td><?php echo $user_row['carrier'];?></td>
					<td><?php echo $user_row['display_name'];?></td>
					<td><a href="edit_user.php?id=<?php echo $user_row['id'];?>">Edit</a> | 
						<a href="" style="cursor:pointer"  onclick="return deleteUser(<?php echo $user_row['id'];?>);">Delete | </a>
						<a href="change_password.php?id=<?php echo $user_row['id'];?>">Change Password</a></td>
					
				</tr>
				<?php $i++;}?>
				<?php if($total_records>$offset){?>
					<tr>
						<td colspan="6">	
							<?php	doPages($offset, 'user_listing.php', '', $total_records); ?>
						</td>
					</tr>
				<?php }?>
				<?php }else{ ?>
					<tr>
						<td colspan="6">No Record Found.</td>
					</tr>
				<?php }?>
			</table>
		</div>
	</div>
</div>

</body>
<script>
function deleteUser(id){
	if (confirm("Are you sure to delete this?")){
		window.location.href="delete_user.php?id="+id;
	}
	return false;
}
</script>
</html>
